package com.forlove.app.qselect.login.presenter;

import android.text.TextUtils;

import com.forlove.app.common.base.mvp.presenter.IBasePresenter;
import com.forlove.app.common.network.ICallBack;
import com.forlove.app.common.utils.LogUtil;
import com.forlove.app.common.utils.ParseHelper;
import com.forlove.app.manager.NetworkManager;
import com.forlove.app.manager.ServerManager;
import com.forlove.app.qselect.CommonEntity;
import com.forlove.app.qselect.login.entity.LimitEntity;
import com.forlove.app.qselect.login.service.IPermissionCheckerService;
import com.forlove.app.qselect.login.service.impl.PermissionCheckerServiceImpl;
import com.forlove.app.qselect.login.view.PermissionCheckerView;

import java.util.Map;

/**
 * Created by yjl on 2017/11/6.
 */

public class PermissionCheckerPresenter extends IBasePresenter {
    private IPermissionCheckerService permissionCheckerService;
    private PermissionCheckerView chekerView;

    public PermissionCheckerPresenter(PermissionCheckerView choiceAgeView) {
        this.chekerView = choiceAgeView;
        if (permissionCheckerService == null) {
            permissionCheckerService = new PermissionCheckerServiceImpl();
            setService(permissionCheckerService);
        }
    }

    public void loadLimitData(Map param) {
        if (param == null) {
            return;
        }
        permissionCheckerService.loadData(ServerManager.ACTION_LIMIT_LOCATION, param, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, String result) {
                LimitEntity limitEntity = ParseHelper.getModel(result, "data", LimitEntity.class);
                LogUtil.e("yjl", "运营限制:" + result);
                chekerView.updateLimitView(limitEntity);
            }

            @Override
            public void onFail(int statusCode, String result) {
                CommonEntity commonEntity = new CommonEntity();
                commonEntity.parseJSONString(result);
                if (!TextUtils.isEmpty(commonEntity.message)) {
                    chekerView.showErrorData(NetworkManager.ResultCode.RESULT_FAIL, commonEntity.message);
                } else {
                    chekerView.showErrorData(NetworkManager.ResultCode.RESULT_ERROR, "稍后重试!");
                }
            }
        });
    }
}
